package com.manbu.springcloud;

import com.manbu.springcloud.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import com.manbu.springcloud.pojo.Dept;

import java.util.List;

/**
 * @description:
 * @author: wanghan
 * @time: 2021/4/19 下午11:17
 */
@RestController
public class DeptController {
    @Autowired
    DeptService deptService;

    @GetMapping("/dept/get/{id}")
    // 多线程方案可以使用线程池
    @HystrixCommand(fallbackMethod="HystrixQueryDeptById")
    @ResponseBody
    public Dept queryDeptById(@PathVariable("id") Long id) {
        Dept dept = deptService.queryDeptById(id);
        if (dept==null){
            throw new RuntimeException("this id =>"+id+" not found or message count not found");
        }
        return deptService.queryDeptById(id);
    }

    public Dept HystrixQueryDeptById( Long id){
        return new Dept().setDname("this id =>"+id+" not found or message count not found-@hystrix").setDeptno(id).setDb_source("not found database in mysql");
    }


}
